from DEFlib import *
import ColorLib
import pygame
import time
import sys
import random
import math
import os

ALLCOLOR = ColorLib.AllColor()

# 初始化字体配置
if True:
    # 加载字体文件
    # 导入系统字体
    FONT1 = resource_path('Assets\\yhxmh.ttf')
    FONT2 = resource_path('Assets\\zhbtt.ttf')
    pygame.font.init()
    font = pygame.font.Font(FONT1, 15)
    almidfont = pygame.font.Font(FONT1, 20)
    midfont = pygame.font.Font(FONT1, 25)
    bigfont = pygame.font.Font(FONT2, 35)


def EndAgain(win, end_surface, WINDOW_SIZE, WINCOLOR):
    blueagainz = pygame.image.load(resource_path('Assets\\blueagain.png')).convert_alpha()
    blueagainz.set_colorkey(ALLCOLOR.white)

    redagainz = pygame.image.load(resource_path('Assets\\redagain.png')).convert_alpha()
    redagainz.set_colorkey(ALLCOLOR.white)

    changeturnwinwidth = 1050 + 5
    showchangeturnwinwidth = -5

    playing = False

    while not playing:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()
                sys.exit()

        end_surface.fill((0, 0, 0, 0))

        showchangeturnwinwidth = nonlinear_move(showchangeturnwinwidth, changeturnwinwidth, 1.5, 0.01)

        pygame.draw.rect(end_surface, WINCOLOR, (-100, 0, showchangeturnwinwidth, WINDOW_SIZE[1]), 640)

        if WINCOLOR == (0, 162, 232):
            end_surface.blit(blueagainz, (showchangeturnwinwidth, 0))
        elif WINCOLOR == (235, 85, 90):
            end_surface.blit(redagainz, (showchangeturnwinwidth, 0))

        win.blit(end_surface, (0, 0))
        pygame.display.flip()

        if int(round(showchangeturnwinwidth, 1)) == 1055:
            playing = True
            againtextlogo = bigfont.render("ConsecutiveChess!!! 版权所有 2024 匡科涵", True, (255, 255, 255))
            againtextlogo_rect = againtextlogo.get_rect()
            end_surface.blit(againtextlogo, (
                (WINDOW_SIZE[0] - againtextlogo_rect[2]) / 2, (WINDOW_SIZE[1] - againtextlogo_rect[3]) / 2))
            win.blit(end_surface, (0, 0))
            pygame.display.flip()
            time.sleep(1.5)
